class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        vector<vector<int>> ans;
        sort(intervals.begin(),intervals.end());
        ans.push_back(intervals[0]);
        int sz=intervals.size();
        for(int i=1;i<sz;i++)
        {
            vector<int> cur=intervals[i];
            vector<int>& last=ans.back();
            if(cur[0]<=last[1])
            {
                last[1]=(cur[1]>last[1]?cur[1]:last[1]);
            }
            else
            {
                ans.push_back(intervals[i]);
            }
        }
        return ans;
    }
};
